<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>非单文件组件基本使用</title>
</head>
<script src="../../../js/vue.js"></script>
<body>
<div class="root">
    <h1>{{msg}}</h1>
    <hr>
    <student></student>
    <hr>
    <school></school>

</div>

<script>

    //创建组件
    const school = Vue.extend({
        //组件注册时不用写el,因为所有组件都要被一个vm实例对象管理,由vm决定服务哪个容器
        template: `
          <div class="demo">
            <h2>学校名称：{{ schoolName }}</h2>
            <h2>学校地址：{{ address }}</h2>
          </div>
        `,
        data() {
            return {
                schoolName: '韩山师范学院',
                address: '广东潮州'
            }
        }
    })

    //简写方式
    const student = {
        template: `
          <div>
            <h2>学生姓名：{{ studentName }}</h2>
            <h2>学生年龄：{{ age }}</h2>
          </div>
        `,
        data() {
            return {
                studentName: '曾宇杰',
                age: 22
            }
        }
    }

    const vm = new Vue({
        el: '.root',
        data: {
            msg: '欢迎学习前端',
        },
        //第二步：注册组件（局部注册)
        components: {
            school,
            student
        }
    })

</script>
</body>
</html>